// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   LightView.java

package jones.gui;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JPanel;
import javax.swing.event.MouseInputAdapter;
import jones.Light;

// Referenced classes of package jones.gui:
//            PositionHandle

public class LightView extends JPanel
    implements Observer
{

    private static int RADIUS = 5;
    private Light light = null;
    private PositionHandle positionHandle = null;

    public LightView(Light light)
    {
        this.light = light;
        init();
    }

    private void init()
    {
        setOpaque(false);
        setCursor(Cursor.getPredefinedCursor(0));
        setFocusable(true);
        setEnabled(true);
        setVisible(true);
        MouseInputAdapter mouseInputAdapter = ((MouseInputAdapter) (new MouseInputAdapter() {

            Point2D offset = null;

            public void mousePressed(MouseEvent e)
            {
                offset.setLocation((double)e.getX() - light.getX(), (double)e.getY() - light.getY());
            }

            public void mouseDragged(MouseEvent e)
            {
                light.setX((double)e.getX() - offset.getX());
                light.setY((double)e.getY() - offset.getY());
                ((Observable) (light)).notifyObservers();
            }

            
            {
                offset = ((Point2D) (new java.awt.geom.Point2D.Double()));
            }
        }
));
        addMouseListener(((java.awt.event.MouseListener) (mouseInputAdapter)));
        addMouseMotionListener(((java.awt.event.MouseMotionListener) (mouseInputAdapter)));
        addMouseListener(((java.awt.event.MouseListener) (new MouseAdapter() {

            public void mousePressed(MouseEvent e)
            {
                requestFocusInWindow();
                repaint();
            }

        }
)));
        requestFocusInWindow();
    }

    public void update(Observable obs, Object obj)
    {
        repaint();
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.setColor(Color.yellow);
        g.fillOval((int)light.getX() - RADIUS, (int)light.getY() - RADIUS, 2 * RADIUS, 2 * RADIUS);
        g.setColor(Color.white);
        g.drawOval((int)light.getX() - RADIUS, (int)light.getY() - RADIUS, 2 * RADIUS, 2 * RADIUS);
    }

    public boolean contains(int x, int y)
    {
        return Point2D.distance(x, y, light.getX(), light.getY()) < (double)RADIUS;
    }


}
